const Express = require("express");
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();
const LogServer = require("../../servers/LogInfo")
//分页获取log
router.get("/getLogInfo", async (req, res) => {
  try {
    const { page, limit } = req.query;
    const result = await LogServer.find(page, limit);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

//添加log记录
router.post("/addLogInfo", async (req, res) => {
  try {
    const result = await LogServer.add(req.body);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

/**
 * 更新log记录
 */
router.post("/updateLogInfo/:id", async (req, res) => {
  const userId = req.params.id;
  const userObj = req.body;
  try {
    const result = await LogServer.update(userId, userObj);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
/**
 * 根据id删除log记录
 */
router.post("/delLogInfo/:id", async (req, res) => {
  try {
    const userId = req.params.id;
    const result = await LogServer.delete(userId);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
/**
 * 查询所有log记录
 */
router.get("/getAllLogInfo", async (req, res) => {
  try {
    const result = await LogServer.findAll();
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});
module.exports = router